import java.awt.EventQueue;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.SQLException;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JTextField;


public class ihmFenetre implements ActionListener {

	private JFrame frame;
	private JTextField txtCb;
	private JButton btnPrendre;
	private JTextField txtPrendre;
	private JButton btnRendre;
	private JTextField txtRendre;
	private JButton btnCb;
	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					ihmFenetre window = new ihmFenetre();
					window.frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the application.
	 */
	public ihmFenetre() {
		initialize();
	}

	/**
	 * Initialize the contents of the frame.
	 */
	private void initialize() {
		frame = new JFrame();
		frame.setSize(250, 200);
		frame.setLocationRelativeTo(null);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.getContentPane().setLayout(new GridLayout(3, 2, 10, 10));
		
		txtPrendre = new JTextField();
		frame.getContentPane().add(txtPrendre);
		txtPrendre.setColumns(10);
		
		btnPrendre = new JButton("Prendre");
		frame.getContentPane().add(btnPrendre);
		btnPrendre.addActionListener(this);
		
		txtRendre = new JTextField();
		frame.getContentPane().add(txtRendre);
		txtRendre.setColumns(10);
		
		btnRendre = new JButton("Rendre");
		frame.getContentPane().add(btnRendre);
		btnRendre.addActionListener(this);
		
		txtCb = new JTextField();
		frame.getContentPane().add(txtCb);
		//textField.setColumns(10);
		

		btnCb = new JButton("Cb");
		frame.getContentPane().add(btnCb);
		btnCb.addActionListener(this);

		try {
			DataBase.getInstance();
			DataBase.connexion();
		} catch (InstantiationException | IllegalAccessException
				| ClassNotFoundException | SQLException e) {
			
			e.printStackTrace();
		}
		
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		if (((JButton) e.getSource()).getText().equals("Prendre")){
			try {
				DataBase.getInstance().setVeloDisponibilite(false, txtPrendre.getText());
			} catch (InstantiationException | IllegalAccessException
					| ClassNotFoundException | SQLException e1) {
				e1.printStackTrace();
			}
		}
		if (((JButton) e.getSource()).getText().equals("Rendre")){
			try {
				DataBase.getInstance().setVeloDisponibilite(true, txtRendre.getText());
			} catch (InstantiationException | IllegalAccessException
					| ClassNotFoundException | SQLException e1) {
				e1.printStackTrace();
			}
		}
		if (((JButton) e.getSource()).getText().equals("Cb")){
			try {
				DataBase.getInstance().setCbCode(txtCb.getText());
			} catch (InstantiationException | IllegalAccessException
					| ClassNotFoundException | SQLException e1) {
				e1.printStackTrace();
			}
		}
	}

}
